<?
if($_POST["selbox"] != ''){

	if($check_me_authed == "OK"){

		$today_date 			= date("d-m-Y");

		$srcDbSequence      = "MST_SEQUENCE";
    $srcDbHdr           = "PCH_HDR";
    $srcDbHdrLog        = "LOG_PCH_HDR";
    $srcDbDtl           = "PCH_DTL";
    $srcDbSubDtl        = "PCH_SUB_DTL";
    $srcDbMstModel      = "MST_MODEL";
    $srcDbInputHistory  = "MODEL_INPUT_HISTORY";
    $srcDbSupplier      = "SUPPLIER";

    $UID     = unserialize($_SESSION["serUID"]);
    $userId  = $UID->getUID();

		$COracle = new oracleDb;
    $COracle->init($_SESSION["ORCL"],
                   $_SESSION["OPASS"],
                   $_SESSION["SID"],
                   _NO_COMMENT);

    if ($COracle->connect()) {


			if(sizeof($_POST["selbox"]) == 0){

				echo "Error nothing to be delete.\n";
			}else{

				foreach($_POST["selbox"] as $delThisJobId){

          /**
      		* Fetch global header
      		* And check the status if it is valid
      		* where STATUS = _NOT_ACTIVE
      		*
      		*/
      		$CFetchers->fetchLstDataHeader($COracle,
                                         $delThisJobId,
                                         $srcDbHdr,
                                         $nHeader,
                                         $lstHeader);

          if($lstHeader["STATUS"][0] == _NOT_ACTIVE){

            /**
          	* Delete the previous entry
          	*
          	*/
          	$CHandlers->dbEntDelete($COracle,
                      	            $delThisJobId,
                      	            $srcDbHdr);

            $CHandlers->dbEntDelete($COracle,
                      	            $delThisJobId,
                      	            $srcDbDtl);

            $CHandlers->dbEntDelete($COracle,
                      	            $delThisJobId,
                      	            $srcDbSubDtl);

            $CHandlers->dbEntDelete($COracle,
                      	            $delThisJobId,
                      	            $srcDbInputHistory);


            /**
            * Insert Log
            *
            */
            $CHandlers->insToDbLog($COracle,
                                   $today_date,
                                   $delThisJobId,
                                   $userId,
                                   $_SERVER["REMOTE_ADDR"],
                                   _DELETE_MODE,
                                   $srcDbHdrLog);

          }else{

            usrDie("Error: Tx is ACTIVE/APPROVED/CANCELED");
          }

			  }

  			$COracle->commit();

  			if($COracle->getStatus() == true){

      	  usrMsg("Delete Complete");
      	}else{

      	  usrMsg("Delete Process Interupted");
      	}

      	$COracle->dc();

  			//jumpTo(2,"../".$_SESSION["source_caller"]);
      }
		}else{

			usrDie("Error: Connection to oracle Failed");
		}
	}else{

		usrDie("Error: Connection to oracle Failed");
	}
}
?>